<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>请假信息管理系统</title>
    <link rel="stylesheet" href="../../css/login.css">
</head>
<body>
    <div class="bodyBox">
        <img src="../../images/登录左侧.png" alt="" class="picture">
        <form class="loginBox" th:action="@{/login}" method="post" id="loginBox">
            <h1>请假信息管理系统</h1>
            <div class="inputBox">
                <img src="../../images/登录.png" alt="">
                <input type="text" name="username" placeholder="用户名" id="username">
            </div>
            <div class="inputBox">
                <img src="../../images/密码（关）.png" alt="">
                <input type="password" name="password" placeholder="密码" id="password">
            </div>
            <div class="checkCodeBox">
                <input type="text" name="checkCode" placeholder="验证码" id="checkCode">
                <img th:src="@{/login/checkCode}" onclick="changeCode()" id="checkCodeImg">
            </div>
            <div class="identity">
                <label for="admin">系统管理员<input type="radio" value="系统管理员" name="identity" id="admin"></label>
                <label for="teacher">辅导员<input type="radio" value="辅导员" name="identity" id="teacher"></label>
                <label for="student">学生<input type="radio" value="学生" name="identity" id="student"></label>
            </div>
            <div class="buttonBox">
                <input type="button" value="登录" onclick="loginHome()" >
<!--                <input type="button" value="注册" onclick="register()">-->
            </div>
        </form>
    </div> 
</body>
<script th:inline="javascript" type="text/javascript">
    function loginHome(){
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        var identity = document.getElementsByName("identity");
        if(username == null) {
            alert("用户名不能为空");
            return false;
        }
        if(password == null){
            alert("密码不能为空");
            return false;
        }
        var checkedIdentity;
        var flag = false;
        for (let i = 0; i < identity.length; i++) {
            if(identity[i].checked) {
                checkedIdentity = identity[i].value;
                flag = true;
                break;
            }
        }
        if(!flag){
            alert("请选择您的身份");
            return false;
        }
        document.getElementById("loginBox").submit();
    }

    var message = [[${resultInfo?.message}]];
    var code = [[${resultInfo?.code}]];
    console.log(message);
    console.log(code);
    if(code != 20011 && code != null) {
        alert(message);
    }

    // function register(){
    //     location.href = 'register.html'
    // }

    function changeCode(){
        document.getElementById("checkCodeImg").src = "/login/checkCode?"+new Date().getMilliseconds();
    }
</script>
</html>